home *** CD-ROM | disk | FTP | other *** search
/ Gigarom 1 / Gigarom Macintosh Archives (Quantum Leap)(CDRM1080320)(1993).iso / FILES / BBS / MUBBS / E-Mail 1.5 source.cpt / E-mail / EnterEmail.c < prev    next >
Text File  |  1992-01-03  |  9KB  |  370 lines

  1. /* *********************************************************************************
  2.      
  3.       MODULE:        EnterEmail Module
  4.       
  5.      DESCRIPTION:    This EnterEmail Module is a simple module for MUBBS, the
  6.                      Multi-User Bulliten Board System Software.
  7.                      
  8.      AUTHOR:        Noam Freedman
  9.      
  10.      Copyright © 1990 by Noam Freedman. Portions are also Copyright Symantec Corp.
  11.  
  12.      This program source code and it's compiled version IS NOT IN THE
  13.      PUBLIC DOMAIN ! Please read the "COPYRIGHT NOTICE / NMF" file for details
  14.      regarding use of this program source code and it's compiled version.
  15.      
  16.      Revision History:
  17.      ============================================================
  18.       8/26/91 - Started programming
  19.      11/ 4/91 - Edited for release
  20.      ============================================================
  21.      
  22.  
  23.     ******************************************************************************** */
  24.  
  25.  
  26. #define        INMAIN
  27.  
  28. #include    "MUBBS Module.h"
  29. #include    <SetUpA4.h>
  30. #include    "Email.h"
  31.  
  32. /* my globals for this module */
  33.  
  34. pascal void main (mode1,G1,P1)
  35.        int mode1;
  36.        struct GS *G1;
  37.        Ptr P1;
  38. {
  39. Handle temph;
  40. float version = 0.5; /* what version of MUBBS you are compatable with IE: .5 and above */
  41. RememberA0(); SetUpA4(); /* This sets up the A4 register to access our globals */
  42. asm { _RecoverHandle }; asm {move.l a0,temph}; HLock(temph); /* locks our module, do this ! */
  43.  
  44. G=G1; /* This MUST be the first thing you do in main only, it sets up the struct globals */
  45. mode[u]=mode1; /* set up our mode so that you can read it anywhere */
  46.  
  47. switch (mode[u]) { /* any un-handled modes return error from this module */
  48.     case 3:
  49.         if (getinfo(P1) != 0){ /* mode 3 because we are passing a user pointer */
  50.             G->moduleresult=0; /* mode 2 doesnt work here, we need a pointer */
  51.             break;
  52.             }
  53.         enteremail(P1);
  54.         G->moduleresult=0;
  55.         break;
  56.     case 98:
  57.         versionck(version); /* just return after this call, don't modify anything */
  58.         break;        
  59.     case 0:
  60.         strcpy (G->programmer,"Noam Freedman"); /* show the programmer's name up to 20 chars*/
  61.         G->moduleresult=0; /* this was also a init call if we need close call put 99 here */
  62.         break;
  63.     default:
  64.         G->moduleresult=1; /* return bad code */
  65.     };
  66.  
  67. HUnlock(temph); /* unlocks this module, do this ! */
  68. RestoreA4(); /* call this when you are all done */
  69. }
  70.  
  71.  
  72. getinfo(S)
  73. struct EnterStruct *S;
  74. {
  75. int num;
  76. char temp[40];
  77.  
  78.  
  79. if (!G->online[u]) { return(2); } /* do this check so we can log out if hang up */
  80.  
  81. strcpy(S->FromUser,G->username[u]);
  82.  
  83. if(S->ToUser[0] != 0) goto skipit; /* if users to name isn't blank */
  84.  
  85. enterit:
  86. send("]]]");
  87. send("Enter the user's name (or \"Sysop\") : ");
  88. portsin(S->ToUser, 33);
  89. send(G->CR[u]);
  90.  
  91. if (S->ToUser[0] == 0)
  92.     {
  93.     send("]]Message Aborted.]");
  94.     S->result = 1;
  95.     return(1);
  96.     }
  97.  
  98. strcpy(temp,S->ToUser);
  99. strtoupper(temp);
  100. if(strcmp(temp,"SYSOP") == 0) {
  101.     strcpy (S->ToUser,G->sysopname); /* get the sysop's name */
  102.     goto skipit;
  103.     }
  104.  
  105. if ( ! getuserinfo(S->ToUser)) { /* see if this user exists */
  106.     send ("]There is no such user as \"%s\" on this system, please try again.]",S->ToUser);
  107.     goto enterit;
  108.     }
  109.  
  110. skipit:
  111. if (S->ToUser[0] != 0)
  112.     {
  113.     send("]]Emailing \"%s\"",S->ToUser);
  114.     send("]]Title: ");        
  115.     portsin(S->title, 69);
  116.     if (S->title[0] != 0)
  117.         {
  118.         S->result = 0;
  119.         return(0);
  120.         }
  121.     else
  122.         {
  123.         send("]]Message Aborted.]");
  124.         S->result = 1;
  125.         return(1);
  126.         }
  127.     }
  128. else
  129.     {
  130.     send("]]Message Aborted.]");
  131.     S->result = 1;
  132.     return(1);
  133.     }
  134. }
  135.  
  136. enteremail(S)
  137. struct EnterStruct *S;
  138. {
  139. char pad[100]; /* this is a fix for a problem */
  140. char ch;
  141. int a = 0,      /* flag */
  142.     i = 0,        /* temp # holder */
  143.     tf = FALSE,    /* true/false flag */
  144.     num;            /* true/false flag when calling functions */
  145. S->numlines = 0; /* num lines */
  146.     
  147. send("]]A line can contain 75 characters, max 50 lines.]");
  148. send("To end or edit, enter a carriage return on an empty line.]");
  149. send("    ---------1---------2---------3---------4---------5---------6---------7----!]");
  150.  
  151. G->nocheck[u]=TRUE; /* no control checking on ouput ! */
  152. if( (S->numlines+1) < 9 )
  153.     send(" %i: ",(S->numlines+1)); /* don't check for anything here */
  154. else                    
  155.     send("%i: ",(S->numlines+1)); /* don't check for anything here */
  156. G->nocheck[u]=FALSE; /* turn it back on */
  157.     
  158. while ( a == 0 )
  159.     {
  160.     if (!G->in()) {num = 2;goto byebye;} /* carrier detect or time out ? */
  161.     ch = G->input[u];
  162.     if ( ch == 13)
  163.         {                                
  164.         G->nocheck[u]=TRUE; /* no control checking on ouput ! */
  165.         send(G->CR[u]); /* don't check for anything here */
  166.         G->nocheck[u]=FALSE; /* turn it back on */
  167.         if (S->numlines >= 49) i = 0;
  168.         else S->numlines = S->numlines + 1;
  169.             
  170.         if (i == 0)
  171.             {
  172.             if(S->numlines <= 48) S->numlines = S->numlines - 2;
  173.             num = askline(S);
  174.             if (num != 0)  goto byebye;
  175.             }
  176.         i = 0;
  177.         S->emailtext[S->numlines][i]= '\0'; 
  178.         G->nocheck[u]=TRUE; /* no control checking on ouput ! */
  179.         if( (S->numlines+1) <= 9 )
  180.             send(" %i: ",(S->numlines+1)); /* don't check for anything here */
  181.         else
  182.             send("%i: ",(S->numlines+1)); /* don't check for anything here */
  183.         G->nocheck[u]=FALSE; /* turn it back on */
  184.         }
  185.     else 
  186.         if ( ch == 8 ) /* handle backspace */
  187.             {
  188.             if (i>0) {
  189.                 G->serout('\b');
  190.                 G->serout(' ');
  191.                 G->serout('\b');
  192.                 i--;
  193.                 S->emailtext[S->numlines][i] = '\0';
  194.                 }
  195.             if (!G->online[u]) {num = 2;goto byebye;} /* time out ? */
  196.             }
  197.     else
  198.         if ( i >= 74 )
  199.             {
  200.             G->serout(ch); /* doesn't check for "S" or "C" */
  201.             if (!G->online[u]) {num = 2;goto byebye;} /* time out ? */
  202.             if (S->numlines >= 49) continue;
  203.             S->emailtext[S->numlines][i] = ch;
  204.             S->emailtext[S->numlines][i+1] = '\0';
  205.             S->numlines = S->numlines + 1;
  206.             i = 0;
  207.             G->nocheck[u]=TRUE; /* no control checking on ouput ! */
  208.             send(G->CR[u]);
  209.             if( (S->numlines+1) <= 9 )
  210.                 send(" %i: ",(S->numlines+1)); /* don't check for anything here */
  211.             else
  212.                 send("%i: ",(S->numlines+1)); /* don't check for anything here */
  213.             G->nocheck[u]=FALSE; /* turn it back on */
  214.             }
  215.     else
  216.         {
  217.         G->serout(ch); /* doesn't check for "S" or "C" */
  218.         if (!G->online[u]) {num = 2;goto byebye;} /* time out ? */
  219.         S->emailtext[S->numlines][i] = ch;
  220.         S->emailtext[S->numlines][i+1] = '\0';
  221.         i++;
  222.         }
  223.     }
  224. byebye:
  225. S->result = num;
  226. }
  227.  
  228.  
  229. askline(S)
  230. struct EnterStruct *S;
  231. {
  232. char tempstring[255], ch;
  233. int num = 0,  /* flag */
  234.     b = 0,  /* flag */
  235.     c = 0,  /* temp variable */
  236.     d = 0;  /* temp variable */
  237.  
  238. while ( b == 0 )
  239.     {                                            
  240.     if (S->numlines == 0 && S->emailtext[0][0] == '\0') /* if no text at all */
  241.         {
  242.         send("]Message Cancelled.]");
  243.         num = 1;
  244.         b = 1;
  245.         break;
  246.         }
  247.     if (!(cmd1("]]>> Continue, Delete line, Edit line, List, Save, Quit : ")))
  248.         {
  249.         G->online[u]=FALSE;
  250.         b = 1;
  251.         num = 2;
  252.         }
  253.     send(G->CR[u]);
  254.     ch = G->input[u];
  255.     switch (ch)
  256.         {
  257.         case 'C':
  258.                 if ( S->numlines <=48 )
  259.                     {
  260.                     S->numlines = S->numlines + 1;
  261.                     num = 0;
  262.                     b = 1;
  263.                     }
  264.                 else
  265.                     send("]Message is already 50 lines!]");
  266.                 break;
  267.         case 'D':
  268.                 send("]Enter line number to delete, or RETURN to exit : ");
  269.                 portsin(tempstring,3);
  270.                 send(G->CR[u]);
  271.                 c = strtoint(tempstring);
  272.                 if (c <= 0) break;
  273.                 if (c > (S->numlines + 1)){
  274.                     send("]]There is no such line number.]]");
  275.                     break;
  276.                     }
  277.                 send("]Line #%d reads:]",c);
  278.                 send(S->emailtext[(c-1)]);
  279.                 cmd1("]]Are you sure you want to DELETE it (Y/N)? ");
  280.                 ch = G->input[u];
  281.                 send(G->CR[u]);
  282.                 if (ch=='Y'){
  283.                     for (d = (c-1); d <S->numlines; d++)
  284.                         strcpy(S->emailtext[d],S->emailtext[d+1]);
  285.                     S->numlines = S->numlines - 1;
  286.                     }
  287.                 else
  288.                     {
  289.                     send("]Line was not deleted.]");
  290.                     }
  291.                 break;
  292.         case 'E':
  293.                 send("]]The edit-line option for the program has been unwritten as of yet.]");
  294.                 break;
  295.         case 'S':
  296.                 if(S->numlines >49) S->numlines=49; /* just to make sure */
  297.                 num = 10;
  298.                 b = 1;
  299.                 break;
  300.         case 'L':
  301.                 for (d = 0;d<=S->numlines && d<=49;d++)
  302.                     {
  303.                     if( (d+1) < 9 )
  304.                         send(" %i: %s]",(d+1),S->emailtext[d]);            
  305.                     else                    
  306.                         send("%i: %s]",(d+1),S->emailtext[d]);
  307.                     if (G->cancel[u]) break; /* did they press cancel? */
  308.                     }
  309.                 send(G->CR[u]);
  310.                 break;
  311.         case 'Q':
  312.                 cmd1("]Are you sure you want to quit (Y/N)? ");
  313.                 ch = G->input[u];
  314.                 send(G->CR[u]);
  315.                 if (ch=='Y')
  316.                     {
  317.                     send("]Message Cancelled.]");
  318.                     num = 1;
  319.                     b = 1;
  320.                     }
  321.                 break;
  322.         }
  323.                     
  324.     }
  325. return(num);
  326. }
  327.  
  328. getuserinfo(gettemp) /* stolen from the "login" module code */
  329. char *gettemp;
  330. {
  331. char tempname[maxnamelength];
  332. char temp1[maxnamelength],temp2[maxnamelength];
  333. char tchar[258];
  334. int count;
  335. long pos;
  336. FILE *stream;
  337.  
  338. if ((stream = fopen(":user:userlist", "r")) == NULL) {
  339.     print("C> FILE ERROR - cannot open :bbsuser:userlist\n");
  340.     send("]FILE ERROR - Can't open the user list file !]");
  341.     return FALSE;
  342.     }
  343. count = 0;
  344. pos=0;
  345. sprintf(temp2,"%-30s",gettemp); /* Prepare the user name for compare */
  346. strtoupper(temp2);
  347.  
  348. while (TRUE){
  349.  
  350.     if(fseek(stream,pos,0) != 0) print("C> Fseek failed\n"); /* go to the record */
  351.     fgets(tchar,33,stream); if (feof(stream)) goto goteof; sscanf(tchar,"%32[^~]",tempname); /* the user's name */
  352.     strcpy(temp1,tempname); /* save the actual name for later */
  353.     strtoupper(tempname);
  354.     if (strcmp(tempname,temp2) == 0) {
  355.         removespaces(temp1); /* takes out trailing spaces */
  356.         strcpy(gettemp,temp1); /* make their name correct */
  357.         fclose(stream);
  358.         return TRUE;
  359.         }
  360.     otheruser(FALSE); /* do switch */
  361.     if ((++count % 10) == 0) {sendnc (".");} /* show dots */
  362.     pos=pos+801; /* move up a record */
  363.     }
  364. goteof:
  365. fclose(stream);
  366. return FALSE;  /* user was not found */
  367.  
  368. }
  369.  
  370.